<?php
class MContract extends CI_Model{

	public function __construct()
    {
        parent::__construct();
    }
    
    function createStaffContract($id, $salaryList, $appraisalList, $amendmentList) {
        if($salaryList != null && count($salaryList) > 0){
            for($i=0; $i < count($salaryList); $i+= 2){
                $data = array( 
                    'StaffContractID' => id_clean($id),
                    'IncreasedDate' => db_clean($salaryList[$i]),
                    'Comment' => db_clean($salaryList[$i+1]),
        		);
        		$this->db->insert('salaryincrease', $data);
            }
        }
        if($appraisalList != null && count($appraisalList) > 0){
            for($i=0; $i < count($appraisalList); $i+= 2){
                $data = array( 
                    'StaffContractID' => id_clean($id),
                    'AppraisalDate' => db_clean($appraisalList[$i]),
                    'Comment' => db_clean($appraisalList[$i+1]),
        		);
        		$this->db->insert('appraisal', $data);
            }
        }
        if($amendmentList != null && count($amendmentList) > 0){
             for($i=0; $i < count($amendmentList); $i+= 2){
                $data = array( 
                    'StaffContractID' => id_clean($id),
                    'AmendmentDate' => db_clean($amendmentList[$i]),
                    'Comment' => db_clean($amendmentList[$i+1]),
        		);
        		$this->db->insert('amendment', $data);
            }
        }
    } 
    
    function getSalaryIncreaseByContractId($id)
    {
         $data = array();
        $this->db->where('StaffContractID',$id);
	    $Q = $this->db->get('salaryincrease');
        if ($Q->num_rows() > 0){
    	   foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
        }
        $Q->free_result();    
        return $data;    
    }
    function getAppraisalByContractId($id)
    {
         $data = array();
        $this->db->where('StaffContractID',$id);
	    $Q = $this->db->get('appraisal');
        if ($Q->num_rows() > 0){
    	   foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
        }
        $Q->free_result();    
        return $data;    
    }
    function getAmendmentByContractId($id)
    {
         $data = array();
        $this->db->where('StaffContractID',$id);
	    $Q = $this->db->get('amendment');
        if ($Q->num_rows() > 0){
    	   foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
        }
        $Q->free_result();    
        return $data;    
    }
}
?>